var vote= new Vue({
    el : '#Votelist',
    data:{
        userId : $("#id").val(),
        xiangmuId:'',
        xiangmu : {},
        votelist:[],
        show : false,
        total:0,
        tongyishu:0,
        butongyishu:0,

        issubmited:false,

        pageIndex : 1,
        pageSize :15,
        pageCount : 0,
        recordCount : 0,
        inputPageIndexValue : "",
    },
    created : function() {
        var _this = this;

        $(".nav navbar-nav li").removeClass("active");
        $("#nav_biaojue").addClass("active");
        _this.findIsacticed();


    },
    methods : {

        findIsacticed:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/xiangmu/getIsactivedxiangmu', {
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.xiangmu = data;
                        _this.xiangmuId=_this.xiangmu.xiangmuid;
                        _this.findBiaojuelist();
                        _this.gettiwaiResultCount();
                        _this.checkIsSubmited();
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        findBiaojuelist:function (){
            var _this = this;
            layer.open({type:3});
            $.post("/tiwaizhenduan/findBiaojuelist",{
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                pageindex : _this.pageIndex,
                pagesize : _this.pageSize,
                rdm : Math.random()
            },function(ppData){
                layer.closeAll("loading");
                if (ppData != null){
                    if(ppData.result == "1"){
                        var data=ppData.resultContent;
                        var mmHtml = "<table class=\"table table-hover table-bordered\" style=\"overflow:hidden; margin-bottom:10px;table-layout:fixed;\" v-if=\"show\" cellspacing=\"0\" cellpadding=\"0\">\n" +
                            "   <thead >\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:60px;\" >序号</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:60px;\" >品种</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:80px;\" >品牌</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:80px;\" >试剂注册证名称</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >规格</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >型号</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >注册证号</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >生产商</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >是否封闭试剂（是/否）</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >平台情况（江苏省/南京市/申请备案）</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >平台编码</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:60px;\" >计价单位</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:80px;\" >平台单价（元）</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >检测项目</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >表决建议</th>\n" +
                            "    </thead>";
                        if(data.TiwaizhenduanList.length > 0){
                            _this.show = true;
                            _this.tiwaizhenduanlist=data.TiwaizhenduanList;

                            var PageInfo = data.PageInfo;
                            _this.pageIndex = PageInfo.pageIndex;
                            _this.recordCount = PageInfo.recordCount;
                            _this.pageCount = PageInfo.pageCount;

                            for (var i = 0; i < data.TiwaizhenduanList.length; i++) {
                                var mmTiwaizhenduan = data.TiwaizhenduanList[i];

                                var mmPinzhong = mmTiwaizhenduan.pinzhong;
                                var mmPinpaiList = mmTiwaizhenduan.pinpailist;
                                var mmPinzhongHebingshu = mmTiwaizhenduan.pinzhonghebinghang;

                                for (var j = 0; j < mmPinpaiList.length; j++) {
                                    var s=0;

                                    var mmPinpailist = mmPinpaiList[j];
                                    var mmPinpai = mmPinpailist.pinpai;
                                    var mmId=mmPinpailist.id;
                                    var mmResult=mmPinpailist.result;
                                    var mmOrdernumber = mmPinpailist.ordernumber;
                                    var mmZhucezhengmingcheng = mmPinpailist.zhucezhengmingcheng;
                                    var mmGuige = mmPinpailist.guige;
                                    var mmXinghao = mmPinpailist.xinghao;
                                    var mmZhucezhenghao = mmPinpailist.zhucezhenghao;
                                    var mmShengchanshang = mmPinpailist.shengchanshang;
                                    var mmShifoufengbi = mmPinpailist.shifoufengbi;
                                    var mmPingtaiqingkuang = mmPinpailist.pingtaiqingkuang;
                                    var mmPingtaibianma = mmPinpailist.pingtaibianma;
                                    var mmjijiadanwei = mmPinpailist.jijiadanwei;
                                    var mmPingtaidanjia = mmPinpailist.pingtaidanjia;
                                    var mmJiancexiangmu = mmPinpailist.jiancexiangmu;
                                    var mmHuanhangfu = "";
                                    var mmyijihe="";
                                    if(j==0 &&s==0){
                                        mmyijihe= "<td style='text-align:center;vertical-align:middle;width: 49px;height: 100%'  rowspan='" + mmPinzhongHebingshu + "'>" + mmPinzhong + "</td>";
                                        s= 1;
                                    }
                                    mmHtml += mmHuanhangfu + "<td style='text-align:center;vertical-align:middle;'>" + mmOrdernumber + "</td>";
                                    mmHtml +=mmyijihe;
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmPinpai + "</td>";
                                    /*mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmZhucezhengmingcheng + "</td>";*/
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a title='" + mmZhucezhengmingcheng + "'>" + mmZhucezhengmingcheng + "</a></td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a title='" + mmGuige + "'>" + mmGuige + "</a></td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmXinghao + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmZhucezhenghao + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmShengchanshang + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmShifoufengbi + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmPingtaiqingkuang + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmPingtaibianma + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmjijiadanwei + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmPingtaidanjia + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmJiancexiangmu + "</td>";

                                    var mmMsgDiv="<div id='div_"+mmPinzhong+"_"+mmPinpai+"' style=\"text-align:center;\"></div>";
                                    if(mmResult==null){
                                        mmMsgDiv="<div id='div_"+mmPinzhong+"_"+mmPinpai+"' style=\"text-align:center;\"> <span  style=\"color:blue\">未表决</span></div>";
                                    }
                                    if(mmResult==1){
                                        mmMsgDiv="<div id='div_"+mmPinzhong+"_"+mmPinpai+"' style=\"text-align:center;\"><span  style=\"color:green\">同意</span></div>";
                                    }
                                    if(mmResult==0){
                                        mmMsgDiv="<div id='div_"+mmPinzhong+"_"+mmPinpai+"' style=\"text-align:center;\"> <span  style=\"color:#ff0000\">不同意</span></div>";
                                    }
                                    var mmBtndiv="<div style=\"text-align:center;\"><input type=\"button\" class=\"btn btn-sm btn-success\" style=\"float: left;width:60px;\" value=\"同 意\" onclick=\"toVote('"+mmId+"','"+mmPinzhong+"','"+mmPinpai+"',1)\">"
                                        +"<input type=\"button\" class=\"btn btn-sm btn-danger\" style=\"float: left;width:60px;\" value=\"不同意\" onclick=\"toVote('"+mmId+"','"+mmPinzhong+"','"+mmPinpai+"',0)\"></div>";
                                    mmHtml +="<td style='text-align:center;vertical-align:middle;width: 49px;height: 100%'" + mmPinzhongHebingshu + ">"+mmMsgDiv+"" + mmBtndiv + "</td>";

                                    // if (j==0) {
                                    //
                                    //     mmHtml +="<td style='text-align:center;vertical-align:middle;width: 49px;height: 100%'" + mmPinzhongHebingshu + ">"+mmMsgDiv+"" + mmBtndiv + "</td>";
                                    // }else {
                                    //
                                    // }

                                    mmHtml += "</tr>";

                                }
                            }

                        }else {
                            _this.show = false;
                        }
                        mmHtml += "</table>";
                        $("#List").html(mmHtml);
                    }else{
                        layer.alert(ppData.message);
                    }
                }

            },"json");
        },



        gettiwaiResultCount:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/tiwaijieguo/getTiWaiResultCount', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.tongyishu=data.tongyiShu;
                        _this.butongyishu=data.butongyiShu;
                        _this.total=data.total;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },
        checkIsSubmited:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/renyuanfenpei/checkIsSubmited', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        if(ppData.resultContent=="1"){
                            _this.issubmited=true;
                        }
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },


        tosubmit:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/renyuanfenpei/submit', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        _this.issubmited=true;
                        layer.alert("提交成功");
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },


        /* toVote:function (ppId,ppIstongyi) {

             var _this = this;
             layer.open({type: 3});
             $.post('/jieguo/toupiao', {
                 id: ppId,
                 userid: _this.userId,
                 result: ppIstongyi,
                 rdm: Math.random()
             }, function (ppData) {
                 layer.closeAll("loading");
                 if (ppData != null) {
                     if (ppData.result == "1") {
                         _this.getYinjinResultCount();
                         if (ppIstongyi == 1) {
                             $("#jieguo" + ppId).html("<span style=\"color:#008000\">同意</span>");
                         }
                         if (ppIstongyi == 0) {
                             $("#jieguo" + ppId).html("<span style=\"color:#ff0000\">不同意</span>");
                         }
                     } else {
                         layer.alert(ppData.message);
                     }
                 }
             }, "json");
         },*/



        /**
         * 合并单元格(如果结束行传0代表合并所有行)
         * @param table1    表格的ID
         * @param startRow  起始行
         * @param endRow    结束行
         * @param col   合并的列号，对第几列进行合并(从0开始)。第一行从0开始
         */
        /* mergeCell: function (tableId, startRow, endRow, col) {
             alert(startRow)
             var tb = document.getElementById(tableId);
             if (col >= tb.rows[0].cells.length) {
                 return;
             }
             if (col == 0) { endRow = tb.rows.length-1; }
             for (var i = startRow; i < endRow; i++) {
                 if (tb.rows[startRow].cells[col].innerHTML == tb.rows[i + 1].cells[0].innerHTML) {
                     tb.rows[i + 1].removeChild(tb.rows[i + 1].cells[0]);
                     tb.rows[startRow].cells[col].rowSpan = (tb.rows[startRow].cells[col].rowSpan | 0) + 1;
                     if (i == endRow - 1 && startRow != endRow) {
                         mc(tableId, startRow, endRow, col + 1);
                     }
                 } else {
                     this.mergeCell(tableId, startRow, i + 0, col + 1);
                     startRow = i + 1;
                 }
             }
          },*/

        //跳到首页
        SetPageIndex : function(){
            this.pageIndex = 1;
        },
        SetPageEnd : function(){
            this.pageIndex = this.pageCount;
        },
        //上一页
        SetPageIndexPrePage : function(){
            var PrePage = ((this.pageIndex -1) <= 0) ? 1 : (this.pageIndex -1);
            this.pageIndex = PrePage;
        },
        //下一页
        SetPageIndexNextPage : function(){
            var NextPage = ((this.pageIndex +1) >= this.pageCount) ? this.pageCount : (this.pageIndex +1);
            this.pageIndex = NextPage;
        },
        //跳转界面
        JumpPage : function(){
            if(this.inputPageIndexValue <= 1){
                this.inputPageIndexValue = 1;
            }else if(this.inputPageIndexValue >= this.pageCount){
                this.inputPageIndexValue = this.pageCount;
            }
            this.pageIndex = this.inputPageIndexValue;
            this.inputPageIndexValue = '';
        },
    },
    watch :{
        //监控分页情况，刷新列表
        pageIndex : function(){

            this.findBiaojuelist();
        }
    }
})